-- ~/.config/nvim/lua/plugins/img-clip.lua
return {
    "HakonHarnes/img-clip.nvim",
    ft = { "markdown" },
    opts = {
        default = {
            dir_path = function()
                local filename = vim.fn.expand("%:t:r")
                return "imgs/" .. filename
            end,
            extension = nil,
            file_name = "%Y%m%d%H%M%S",
            relative_to_current_file = true,
            -- ✅ 用函数移除扩展名
            template = function(info)
                local name = info.file_name:gsub("%.%w+$", "")
                return "![" .. name .. "](" .. info.file_path .. ")"
            end,
            insert_mode_after_paste = false,
        },
        filetypes = {
            markdown = {
                -- ✅ 同样移除扩展名
                template = function(info)
                    local name = info.file_name:gsub("%.%w+$", "")
                    return "![" .. name .. "](" .. info.file_path .. ")"
                end,
                download_images = false,
            },
        },
    },
    keys = {
        {
            "<leader>p",
            "<cmd>PasteImage<cr>",
            desc = "Paste image from clipboard",
            mode = "n",
        },
    },
    config = function(_, opts)
        require("img-clip").setup(opts)

        vim.api.nvim_create_user_command("PasteImage", function()
            require("img-clip").paste_image()
        end, {})
    end,
}

